<template>
    <div class="wrapper">
        <HeaderNav title="购物车"></HeaderNav>
        <div class="shopCarts" v-if="$store.state.shopcart.shopcartItems.length>0">
            <ShopcartItem :item="item" v-for="item in $store.state.shopcart.shopcartItems"
                          :key="item.objectId"></ShopcartItem>
        </div>
        <div v-if="$store.state.shopcart.shopcartItems.length==0">
            <div class="null1_2R6Nx"><img
                    src="//img11.360buyimg.com/jdphoto/s180x180_jfs/t18163/292/540553659/74408/adeb7463/5a93c51cN3bb5e37b.png"
                    class="empty_icon">
                <p class="empty_txt">购物车空空如也，去<strong><a href="/">首页</a></strong>逛逛吧~</p></div>
        </div>
        <div class="bottom">
            <div class="left">
                总计：￥{{totalPrice}}
            </div>
            <div class="buy_it_now_wrapper">
                <div class="buy_it_now" @click="buy_it_now">立刻购买</div>
            </div>

        </div>
    </div>
</template>
<script>
    import HeaderNav from '../../components/HeaderNav'
    import withStore from "../../vuex/withStore";
    import ShopcartItem from './shopItem'
    import {get_shop_cart_items} from "../product/shopcartModal/service";
    import {isLogin} from "../../utils";
    import myalert from "../../utils/myalert";
    import {make_order} from "./service";
    import order from "../../vuex/model/order";

    export default withStore({
        components: {
            HeaderNav, ShopcartItem
        },
        methods: {
            buy_it_now() {
                var self = this
                if (!isLogin()) {
                    myalert.fail("请登录")
                    return false
                }
                if (this.totalPrice == 0) {
                    myalert.fail("还没有商品")
                    return false
                }
                this.$router.push("/order")
            }
        },
        computed: {
            totalPrice() {
                var a = 0
                var select_array = this.$store.state.shopcart.select_array
                select_array.map(item => {
                    a += item.totalPrice * item.quantity
                })
                return a.toFixed(2)
            }
        },
        data() {
            return {
                total_price: 0,
            }
        },
        mounted() {
            var self = this
            get_shop_cart_items().then(res => {
                self.setStore("shopcart.shopcartItems", JSON.parse(JSON.stringify(res)))
                self.setStore("shopcart.select_array", JSON.parse(JSON.stringify(res)))
            })
        }
    })
</script>
<style lang="less" scoped>
    .wrapper {
        .null1_2R6Nx {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            margin-top: 20px;
        }
        .bottom {
            display: flex;
            align-items: center;
            position: fixed;
            bottom: 0;
            width: 100%;
            max-width: 750px;
            padding-left: px2rem(20);
            height: 45px;
            border-top: 1px solid #eee;
            .buy_it_now_wrapper {
                flex: 1;
                display: flex;
                justify-content: center;
                .buy_it_now {
                    width: 2rem;
                    height: .36rem;
                    background-image: linear-gradient(90deg, #ff4e00, red);
                    color: #fff;
                    display: flex;
                    justify-items: center;
                    align-items: center;
                    border-radius: 50px;
                    font-size: .11rem;
                    justify-content: center;
                }
            }

        }
    }
</style>